// Package sms
// Created by GoLand
// @User: lenora
// @Date: 2023/12/29
// @Time: 13:08

package sms

import "github.com/golang-jwt/jwt/v5"

type AuthService interface {
	Decode(tplToken string) (string, error)
}

type authService struct {
	key []byte
}

func NewAuthService(key []byte) AuthService {
	return &authService{
		key: key,
	}
}

func (s *authService) Decode(tplToken string) (string, error) {
	var claims SmsClaims
	_, err := jwt.ParseWithClaims(tplToken, &claims, func(token *jwt.Token) (interface{}, error) {
		return s.key, nil
	})
	if err != nil {
		return "", err
	}
	return claims.Tpl, nil
}

type SmsClaims struct {
	jwt.RegisteredClaims
	Tpl string
}
